package priv.yiyuan.example.design;

import java.io.IOException;

/**
 * 压缩装饰器
 *
 * @author YiYuan
 * @data 2025/8/8
 * @apoNote
 */
public class CompressionDecorator extends DataReaderDecorator {

    public CompressionDecorator(DataReader wrappedReader) {
        super(wrappedReader);
    }

    @Override
    public String read() throws IOException {

        String originalData = wrappedReader.read();
        return this.compress(originalData);

    }

    private String compress(String data) {
        return "Compressed(" + data.length() + " chars): " + data.substring(0, Math.min(20, data.length())) + "...";
    }

    @Override
    public String getSourceInfo() {
        return "[Compressed] " + wrappedReader.getSourceInfo();
    }
}
